﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using TabbedTemplate.Models;
using TabbedTemplate.Services;
using TabbedTemplate.ViewModels;
using UnitTest.Helpers;

namespace UnitTest.ViewModels
{
    public class TestStoreCollectionsPageViewModel
    {
        [Test]
        public async Task TestStoreTappedCommand()
        {
            var mockPunchNavigationService = new Mock<IPunchNavigationService>();
            var punchNavigationServiceMock = mockPunchNavigationService.Object;
            var storefavorite = new StoreFavorite(null,null,new DateTime());
            var StoreCollectionsPageViewModel =
                new StoreCollectionsPageViewModel(null, null, punchNavigationServiceMock);
            await StoreCollectionsPageViewModel.StoreTappedCommandFunction(storefavorite);
            mockPunchNavigationService.Verify(p=>p.UserPageNavigationToAsync(
                ContentNavigationConstant.StorePunchesPage, storefavorite.Store),Times.Once);
        }

        [Test]
        public async Task TestPageAppearingCommand()
        {
            var mockStoreStorage = new Mock<IStoreStorage>();
            var storeStorageMock = mockStoreStorage.Object;

            var favoriteStorage = await FavoriteStorageHelper.GetInitializedFavoriteStorage();
            Favorite favorite = new Favorite
            {
                StoreUid = "123",
                IsFavorite = true,
                Timestamp = 1
            };
            favoriteStorage.SaveFavoriteAsync(favorite, true);
            var favorites = await favoriteStorage.GetFavoritesAsync();
            var StoreCollectionsPageViewModel =
                new StoreCollectionsPageViewModel(favoriteStorage, storeStorageMock, null);
            var statusList = new List<string>();
            StoreCollectionsPageViewModel.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(TabbedTemplate.ViewModels.StoreCollectionsPageViewModel.Status))
                {
                    statusList.Add(StoreCollectionsPageViewModel.Status);
                }
            };
            await StoreCollectionsPageViewModel.PageAppearingCommandFunction();
            Assert.AreEqual(TabbedTemplate.ViewModels.StoreCollectionsPageViewModel.Loading,statusList[0]);
            var a = statusList.Count;
            Assert.AreEqual(TabbedTemplate.ViewModels.StoreCollectionsPageViewModel.NoMoreResult,statusList[a-1]);
        }
    }
}
